﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wpf.CommonTools.SystemExtension
{
    /// <summary>
    /// 
    /// </summary>
    public class UILanguage
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string FindResource(string key)
        {
            if (System.Windows.Application.Current == null)
            {
                return key;
            }
            else
            {
                object o = System.Windows.Application.Current.FindResource(key);
                return o == null ? key : o.ToString();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string TryFindResource(string key, string defaultValue = null)
        {
            if (System.Windows.Application.Current == null)
            {
                return key;
            }
            else
            {
                object o = System.Windows.Application.Current.TryFindResource(key);
                return o == null ? (defaultValue ?? key) : o.ToString();
            }
        }
    }
}
